import Clouds from "./Clouds";
import CoinItem from "./CoinItem";
import { LanguageComponent } from "./language/LanguageComponent";
import { LanguageManager } from "./language/LanguageManager";
import PkItem from "./PkItem";
import RESSpriteFrame from "./RESSpriteFrame";
import Anim from "./utils/Anim";
import EffectUtils from "./utils/EffectUtils";
import GuideEffect from "./utils/GuideEffect";
import MoneyChange from "./utils/MoneyChange";
import NotifyEffect from "./utils/NotifyEffect";
import Utils from "./utils/Utils";


const { ccclass, property } = cc._decorator;

@ccclass
export default class GameUI extends cc.Component {
    @property(cc.Node)
    private moneyBox:cc.Node = null
    @property(cc.Prefab)
    private moneyPre:cc.Prefab = null
    @property(cc.Node)
    private secondClickBtn:cc.Node = null
    @property(cc.Node)
    private lastClickBtn:cc.Node = null
    @property(cc.Node)
    private clickTargetArr:cc.Node[] = []
    //横屏
    @property(cc.Node)
    private horPayNode:cc.Node = null
    @property(cc.Node)
    private verPayNode:cc.Node = null
    @property(cc.Node)
    private topNode:cc.Node = null
    @property(cc.Node)
    private bottomNode:cc.Node = null
    @property(cc.Node)
    private talkNode:cc.Node = null
    @property(cc.Node)
    private guideFinger:cc.Node = null
    @property(cc.Node)
    private tipNode: cc.Node = null
    @property(cc.Node)
    private startGameMask: cc.Node = null
    @property(cc.Prefab)
    private lightPre: cc.Prefab = null
    @property(cc.SpriteFrame)
    private cloudSpriteFrameArr:cc.SpriteFrame[] = []
    @property(cc.Node)
    private smallCloudsBox: cc.Node = null  // 装半圆发散小云的容器
    @property(cc.Prefab)
    private cloudePre: cc.Prefab = null
    @property({ type: cc.Node, tooltip: CC_DEV && '四周发散动画的小云数组' })
    private samllNodeArr: cc.Node[] = []
    @property(cc.Node)
    private cloudArr: cc.Node[] = [];
    @property(cc.Node)
    private targetArr: cc.Node[] = []
    @property(cc.Node)
    private contentNode: cc.Node = null
    @property(cc.Prefab)
    private pkPrefab: cc.Prefab = null
    @property(cc.Node)
    private mask: cc.Node = null;
    @property(cc.Label)
    private tipLabel: cc.Label = null;
    @property(cc.Label)
    private tipLabel1: cc.Label = null;
    @property(cc.Sprite)
    private bg: cc.Sprite = null
    @property(cc.SpriteFrame)
    private bgArr: cc.SpriteFrame[] = []
    @property(cc.Node)
    private cashOutBtn: cc.Node = null;
    @property(cc.Node)
    private finger: cc.Node = null;
    @property(cc.Node)
    private fingerLight:cc.Node = null
    @property(cc.Label)
    private monlabel: cc.Label = null;
    @property(cc.Label)
    private horMonlabel: cc.Label = null;
    //弹窗
    @property(cc.ParticleSystem)
    private moneyPar:cc.ParticleSystem = null
    @property(cc.Node)
    private colorFlow:cc.Node = null;
    @property(cc.Node)
    private titleNode:cc.Node = null
    @property(cc.Node)
    private resultBtn:cc.Node = null
    @property(cc.Node)
    private resultNode: cc.Node = null;
    @property(cc.Node)
    private resultLight:cc.Node = null;

    private clickTime: number = 0
    private clickFlag: boolean = true
    private monerChange: MoneyChange = null;
    private horMonerChange: MoneyChange = null;
    private amount: number = 0
    private bgmAudioFlag: boolean = true
    private canPlayMusic: boolean = false
    private pkArr: cc.Node[][] = []
    protected start(): void {
        PlayerAdSdk.init();
        this.resize()
        let that = this;
        /**屏幕旋转尺寸改变 */
        cc.view.setResizeCallback(() => {
            that.resize();
        })
        cc.find('Canvas').on('touchstart', () => {
            this.canPlayMusic = true
            this.bgmAudioFlag && cc.audioEngine.play(RESSpriteFrame.instance.bgmAudioClip, false, 1)
            this.bgmAudioFlag = false
            if(this.clickTime==0){
                // this.clickFunc(null,null,1)
            }
        })
        this.secondClickBtn.active = this.lastClickBtn.active = false
        this.startGameMask.active = this.tipNode.active = this.guideFinger.active = true
        Utils.SetScale(this.tipNode, 1.25, 1.2, 0.4, true)
        this.titleNode.active = this.resultBtn.active = false
        this.monerChange = new MoneyChange(this.monlabel, false, this.amount)
        this.horMonerChange = new MoneyChange(this.horMonlabel, false, this.amount)
        this.monlabel.string = this.horMonlabel.string = `0`
        console.log(this.getRandomInt(-0.5, 0.5));
        this.resize()
        this.initGame()
    }
    //初始化界面
    private initGame() {
        for (let i = 0; i < this.cloudArr.length; i++) {
            this.cloudArr[i].active = false
        }
        let countArr = [13, 1, 13, 1, 13, 1]
        let nameArr = ['r', 'b', 'b', 'b', 'rb', 'b']
        let indexArr = [3, 0, 2, 0, 1]
        let parentArr = [3, 0, 2, 0, 1]
        let posArr = [-500, 0, -70, 0, 360]
        for (let i = 0; i < indexArr.length; i++) {
            if (indexArr[i] != 0) {
                this.pkArr[indexArr[i]] = []
            }
        }
        //创建扑克
        for (let index = 0; index < countArr.length; index++) {  //五列
            for (let i = countArr[index]; i > 1; i--) {
                let pkNode = cc.instantiate(this.pkPrefab)
                let item = pkNode.getComponent(PkItem)
                // item.node.parent = this.contentNode
                item.node.parent = this.targetArr[parentArr[index]]
                item.initItem(nameArr[index], i, cc.v2(posArr[index], i * 42 - 740))
                item.node.scale = 1.2
                if (index == 0 || index == 2 || index == 4) {
                    this.pkArr[indexArr[index]][i - 1] = item.node
                }
            }
        }
    }
    private getRandomInt(min: number, max: number) {
        // return Math.floor(Math.random() * (max - min + 1)) + min;
        return parseFloat((Math.random() * (max - min) + min).toFixed(1))
    }
    private getRandomIntFloor(min: number, max: number) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    //扑克移动动画
    private clickFunc(e, eventData,indexQ) {
        // console.log('jayIndex',indexQ,'jaytargte',e.target);
        if (this.clickFlag) {
            this.clickFlag = false
            let index;
            let targetNode = null
            if(e == null || eventData == null){
                targetNode = this.clickTargetArr[indexQ-1]
                index = indexQ
            }else{
                index = Number(eventData)
                targetNode = e.target
            }
            if(e.target.name == 'zhezhao' || e.target.name == 'secondClickBtn' || e.target.name == 'lastClickBtn'){
                targetNode = this.clickTargetArr[index-1]
            }
            cc.audioEngine.play(RESSpriteFrame.instance.clickAudioClip,false,1)
            this.startGameMask.active = false
            this.guideFinger.active = false
            this.talkNode.active = false
            this.clickTime++
            if(this.clickTime == 1){
                this.secondClickBtn.active = true
            }
            if(this.clickTime == 2){
                this.secondClickBtn.active = false
                this.lastClickBtn.active = true
            }
            if (this.clickTime >= 3){
                this.tipNode.active = this.lastClickBtn.active = false
            }
            let originPos = targetNode.parent.convertToWorldSpaceAR(targetNode.position)   //回到原始位置
            console.log('jya',this.targetArr[index],this.targetArr,targetNode);
            targetNode.parent = this.targetArr[index]
            originPos = targetNode.parent.convertToNodeSpaceAR(originPos)
            targetNode.position = originPos
            this.targetArr[index].setSiblingIndex(this.targetArr.length)
            this.targetArr[index].zIndex = 10
            targetNode.setSiblingIndex(20)
            let pos = this.targetArr[index].parent.convertToWorldSpaceAR(this.targetArr[index].position)
            pos = this.samllNodeArr[0].parent.convertToNodeSpaceAR(pos)
            let Pos = this.targetArr[index].parent.convertToWorldSpaceAR(cc.v3(this.targetArr[index].x, this.targetArr[index].y - 25, 0))
            let targetPos = targetNode.parent.convertToNodeSpaceAR(Pos)
            setTimeout(() => {
                this.cloudDisAni(pos, this.samllNodeArr, index)
            }, 700);
            cc.tween(targetNode)
                .to(0.8, { position: targetPos }, { easing: 'quadOut' })
                .call(() => {
                    cc.audioEngine.play(RESSpriteFrame.instance.pukePutAudioClip,false,1)
                    targetNode.setSiblingIndex(0)
                    for (let i = 1; i < this.pkArr[index].length; i++) {
                        targetPos = this.pkArr[index][i].parent.convertToNodeSpaceAR(Pos)
                        cc.tween(this.pkArr[index][i]).delay(0.1 * i)
                            .call(() => {
                                cc.audioEngine.play(RESSpriteFrame.instance.pukePutAudioClip,false,1)
                                if (i == this.pkArr[index].length - 1) {
                                    this.targetArr[index].zIndex = 1
                                    //这里做金纸币动画
                                    // this.moneyAnim(index)
                                    let xArr = [0,-50,100,250]
                                    let xArr1 = [0,-50,200,450]
                                    this.moneyBox.zIndex = 40
                                    let isVerTical = cc.winSize.height > cc.winSize.width
                                    this.moneyBox.x = isVerTical ? xArr[index] : xArr1[index]
                                    if(!isVerTical){
                                        this.moneyBox.y = 400
                                    }
                                    let flyPos = Utils.getLocalPositionWithOtherNode(this.targetArr[index],this.monlabel.node)
                                    let flyPos1 = Utils.getLocalPositionWithOtherNode(this.targetArr[index],this.horMonlabel.node)
                                    flyPos = cc.winSize.height > cc.winSize.width ? flyPos : flyPos1
                                    Anim.ins().ShowFlyAni(this.moneyPre,this.moneyBox,15,flyPos)
                                }
                            })
                            .to(0.25, { zIndex: i, position: targetPos }, { easing: 'quadOut' }).start()
                    }
                }).start()
        }
    }
    private moneyAnim(index:number){
        let moneyNums:number = 9
        let raduis =  130 // 半径
        let angle = 365 / moneyNums
        for(let i =0; i < moneyNums; i++){
            let money = cc.instantiate(this.moneyPre).getComponent(CoinItem)
            money.node.parent = this.moneyBox
            this.moneyBox.zIndex = 40
            money.node.setPosition(cc.v2(0,0))
            let targetX = Math.cos(angle * (i+1) * Math.PI / 180) * raduis
            let targetY = Math.sin(angle * (i+1) * Math.PI / 180) * raduis
            cc.tween(money.node)
            .parallel(
                cc.tween().by(0.04 * this.getRandomIntFloor(3,5),{x:targetX,angle:this.getRandomInt(-180,180)}),
                cc.tween().by(0.06 * this.getRandomIntFloor(3,5),{y:targetY,angle:this.getRandomInt(-180,180)})
            )
            .start()
        }
    }
    //云散开动画 index是飞到目标的索引
    private cloudDisAni(pos: any, nodeArr: cc.Node[], index: number) {
        for (let i = 0; i < nodeArr.length; i++) {
            nodeArr[i].active = false
            nodeArr[i].position = pos
            nodeArr[i].color = cc.Color.WHITE
            nodeArr[i].scale = 1
            nodeArr[i].active = true
            nodeArr[i].opacity = 255
        }
        let disX = nodeArr[0].width
        let disY = nodeArr[0].height
        let randomScale, cloudRandomX, cloudRandomY = null
        let cloudXRandomArr = [1, 1, -1.3, -1]
        let cloudYRandomArr = [1.6, -1, 1.4, -1]
        let startPos = this.targetArr[index].parent.convertToWorldSpaceAR(cc.v3(this.targetArr[index].x, this.targetArr[index].y - 100, 0))
        this.cloudArr.forEach((item)=>{
            item.parent = this.targetArr[index]
        })
        startPos = this.cloudArr[0].parent.convertToNodeSpaceAR(startPos)
        for (let i = 0; i < nodeArr.length; i++) {
            let cloud = nodeArr[i]
            randomScale = this.getRandomInt(0.3, 0.6)
            cloudRandomX = this.getRandomInt(0.2, 0.4)
            cloudRandomY = this.getRandomInt(0.3, 0.5)
            cc.tween(cloud).delay(0.01 * i)
                .to(0.25, { color: cc.color(240, 240, 240, 240), opacity: 200, x: cloud.x + (cloudXRandomArr[i] * this.getRandomInt(5, 10)), y: cloud.y + (cloudYRandomArr[i] * this.getRandomInt(10, 30)) })
                .call(() => {
                    if (i == nodeArr.length - 1) {
                        setTimeout(() => {
                            this.storeUp(this.targetArr[index], () => {
                                this.flagDown(index)
                                this.monlabel.string = `${LanguageManager.instance.formatUnit(100 * this.clickTime)}`
                                Utils.SetScale(this.monlabel.node,1.6,1,0.25,false,1)
                                this.horMonlabel.string = `${LanguageManager.instance.formatUnit(100 * this.clickTime)}`
                                Utils.SetScale(this.horMonlabel.node,1.6,1,0.25,false,1)
                            })
                        }, 600);
                    }
                    this.cloudAnim(startPos)

                    cc.tween(cloud).parallel(
                        cc.tween().to(0.7, { x: cloud.x + (cloudXRandomArr[i] * cloudRandomX * disX) }),
                        cc.tween().to(0.7, { y: cloud.y + (cloudYRandomArr[i] * cloudRandomY * disY) }),
                        cc.tween().to(0.7, { scale: randomScale }),
                        cc.tween().to(0.7, { color: cc.color(180,180,180,180) }),   //cc.Color.GRAY
                        cc.tween().to(0.7, { opacity: 100 })
                            .call(() => {
                                cloud.active = false
                                cloud.opacity = 255
                            })
                    ).start()
                }).start()
        }
    }
    //云左右向上移动的动画
    private cloudAnim(startPos: any) {
        this.cloudArr[0].position = cc.v3(startPos.x, startPos.y, 0)
        this.cloudArr[1].position = cc.v3(startPos.x + 80, startPos.y, -100)
        //创建二维数组用于存储半圆散开动画小云节点
        let cloudsArr: cc.Node[][] = []
        let numRows = 2
        for (let i = 0; i < numRows; i++) {
            cloudsArr[i] = []
        }
        for (let i = 0; i < this.cloudArr.length; i++) {
            setTimeout(() => {
                this.cloudArr[i].opacity = 255
                this.cloudArr[i].active = true
                // i == 0 && this.monerChange.play(LanguageManager.instance.formatUnit(this.clickTime * 100), 1.5, () => { }, this)
                // i == 0 && this.horMonerChange.play(LanguageManager.instance.formatUnit(this.clickTime * 100), 1.5, () => { }, this)
            }, 200);
            cc.tween(this.cloudArr[i]).delay(0.02 * (i + 1) + 0.15)
                .to(0.07, { scale: 0.65, position: cc.v3(this.cloudArr[i].x + 30, this.cloudArr[i].y + 10, 0) }, { easing: 'quadOut' })
                .to(0.08, { scale: 0.78, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(-70,-40), this.cloudArr[i].y + i* this.getRandomInt(13,20), 0) }, { easing: 'quadOut' })
                .to(0.03, { scale: 0.81, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(-20,35), this.cloudArr[i].y + i* this.getRandomInt(20,29), 0) }, { easing: 'quadOut' })
                .to(0.04, { scale: 0.7, position: cc.v3(this.cloudArr[i].x - 60, this.cloudArr[i].y + 45, 0) }, { easing: 'quadOut' })
                .to(0.06, { scale: 0.79, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(5,34), this.cloudArr[i].y + 70, 0) }, { easing: 'quadOut' })
                .to(0.02, { scale: 0.83, position: cc.v3(this.cloudArr[i].x - 60, this.cloudArr[i].y + 75, 0) }, { easing: 'quadOut' })
                .to(0.07, { scale: 0.8, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(-10,30), this.cloudArr[i].y + 103, 0) }, { easing: 'quadOut' })
                .call(()=>{
                // this.cloudArr[i].getComponent(cc.Sprite).spriteFrame = this.cloudSpriteFrameArr[this.getRandomIntFloor(1,3)]
                cc.tween(this.cloudArr[i])
                .to(0.07, { color:cc.color(240,240,240,240),scale: 0.73, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(-40,-10), this.cloudArr[i].y + 18, 0) }, { easing: 'quadOut' })
                .to(0.06, { color:cc.color(220,220,220,220),scale: 0.67, position: cc.v3(this.cloudArr[i].x + 30, this.cloudArr[i].y + 23, 0) }, { easing: 'quadOut' })
                .to(0.04, { color:cc.color(200,200,200,200),scale: 0.81, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(-70,-40), this.cloudArr[i].y + 35, 0) }, { easing: 'quadOut' })
                .to(0.08, { color:cc.color(185,185,185,185),scale: 0.70, position: cc.v3(this.cloudArr[i].x + 28, this.cloudArr[i].y + 43, 0) }, { easing: 'quadOut' })
                .to(0.06, { color:cc.color(185,185,185,185),scale: 0.81, position: cc.v3(this.cloudArr[i].x +this.getRandomInt(-30,0), this.cloudArr[i].y + 45, 0) }, { easing: 'quadOut' })
                .to(0.04, { color:cc.color(170,170,170,170),scale: 0.74, position: cc.v3(this.cloudArr[i].x - 8, this.cloudArr[i].y + 55, 0) }, { easing: 'quadOut' })
                .to(0.02, { color:cc.color(170,170,170,170),scale: 0.62, position: cc.v3(this.cloudArr[i].x + 20, this.cloudArr[i].y + 63, 0) }, { easing: 'quadOut' })
                .to(0.03, { color:cc.color(165,165,165,165),scale: 0.70, position: cc.v3(this.cloudArr[i].x -10, this.cloudArr[i].y + 79, 0) }, { easing: 'quadOut' })
                .call(() => {  //云半圆发散事件
                    let clouds = []
                    let raduis = 150 //半圆发散半径
                    let boxPos = this.cloudArr[i].parent.convertToWorldSpaceAR(cc.v2(this.cloudArr[i].x, this.cloudArr[i].y))
                    boxPos = this.smallCloudsBox.parent.convertToNodeSpaceAR(boxPos)
                    this.smallCloudsBox.setPosition(boxPos)
                    let cloudPos = this.cloudArr[i].parent.convertToWorldSpaceAR(this.cloudArr[i].position)
                    for (let t = 0; t < 7; t++) {
                        clouds[t] = cc.instantiate(this.cloudePre).getComponent(Clouds).node
                        clouds[t].getComponent(Clouds).initItem(this.getRandomIntFloor(0,3),this.getRandomInt(0.5,1.5))
                        clouds[t].parent = this.smallCloudsBox
                        // clouds.setPosition(cc.v2(0,0))
                        cloudPos = clouds[t].parent.convertToNodeSpaceAR(cloudPos)
                        clouds[t].setPosition(cc.v2(0, 0))  //cloudPos   这里重合了
                        cloudsArr[i].push(clouds[t])
                        cc.tween(this.cloudArr[i]).to(0.5, { opacity: 0 }).call(() => {
                            this.cloudArr[i].active = false
                            this.cloudArr[i].opacity = 255
                        }).start()
                    }
                    let angle = 140 / cloudsArr[i].length
                    for (let j = 0; j < cloudsArr[i].length; j++) {
                        let scale = this.getRandomInt(0.2, 0.6)
                        let targetX = Math.cos(angle * (j + 1) * Math.PI / 180) * raduis
                        let targetY = Math.sin(angle * (j + 1) * Math.PI / 180) * raduis
                        cc.tween(cloudsArr[i][j])
                            .parallel(
                                cc.tween().by(1.1, { position: cc.v2(targetX, targetY) }),
                                cc.tween().to(1.1, { color: cc.color(180,180,180,180) }),
                                cc.tween().to(1.1, { opacity: 0 }),
                                cc.tween().to(1.1, { scale: scale })
                            ).start()
                    }
                })
                .start()
                }).start()
                
        }

    }
    private storeUp(node: cc.Node, cb: Function) {
        let store = node.getChildByName('store').getComponent(cc.Sprite);
        store.node.zIndex = 20
        let scheduledFunction = () => this.UpFunc(store, cb); // 保持函数引用一致
        // 存储函数引用以便之后使用
        store['scheduledFunction'] = scheduledFunction;
        this.schedule(scheduledFunction, 1 / cc.director.getAnimationInterval());
    }
    //旗帜下降--icon显示
    private flagDown(index: number) {
        let flagNode = this.targetArr[index].getChildByName(`Mask${index}`)
        // flagNode.setSiblingIndex(this.targetArr[index].children.length)
        flagNode.zIndex = 22
        let lightNode = cc.instantiate(this.lightPre)
        lightNode.parent = this.contentNode
        lightNode.scale = 0.5
        lightNode.active = false
        let startPos = this.targetArr[index].parent.convertToWorldSpaceAR(cc.v3(this.targetArr[index].x, this.targetArr[index].y - 20, 0))
        cc.tween(flagNode)
            .to(0.2, { scaleY: 1.2 })
            .to(0.1, { scaleY: 1 })
            .call(() => {
                let icon = this.targetArr[index].getChildByName(`icon${index}`)
                icon.scale = 3
                icon.zIndex = 30
                cc.audioEngine.play(RESSpriteFrame.instance.bigoAudioClip,false,1)
                setTimeout(() => {
                    icon.active = true
                    cc.tween(icon)
                        .to(0.4, { scale: 1 }, { easing: 'cubicIn' })
                        .call(() => {
                            startPos = lightNode.parent.convertToNodeSpaceAR(startPos)
                            lightNode.position = startPos
                            lightNode.active = true
                            if(this.clickTime>=3){
                                let startScale = cc.winSize.height > cc.winSize.width ? 1.1 : 1.5
                                let endScale = cc.winSize.height > cc.winSize.width ? 1 : 1.4
                                Utils.showUI(this.resultNode,RESSpriteFrame.instance.comeOutAudioClip,0,true,startScale,endScale,()=>{
                                    cc.audioEngine.play(RESSpriteFrame.instance.bigWinAudioClip,false,1)
                                    this.moneyPar.node.active =true
                                    this.colorFlow.active = true
                                    this.titleNode.scale = 3.3
                                    this.titleNode.active = true
                                    cc.tween(this.titleNode)
                                    .to(0.35,{scale:1},{'easing':'quadOut'})
                                    .call(()=>{
                                        setTimeout(() => {
                                            this.resultBtn.scale = 3
                                            this.resultBtn.active = true
                                        }, 500);
                                        cc.tween(this.resultBtn).delay(0.55)
                                        .to(0.35,{scale:1},{'easing':'quadOut'})
                                        .call(()=>{
                                            Utils.SetScale(this.resultBtn,1.1,1,0.3,true)    
                                        })
                                        .start()
                                    }).start()
                                    NotifyEffect.shakeShowUI(this.resultNode,null,()=>{
                                        this.resultLight.getComponent(cc.Animation).play('lightfly')
                                    },1.6,startScale,0.04,5)
                                    cc.audioEngine.play(RESSpriteFrame.instance.cherrUpAudioClip,false,1)
                                    this.mask.active = true
                                    GuideEffect.RotateGuideEffect(this.finger,this.fingerLight)
                                })
                            }
                            cc.tween(lightNode)
                                .to(1.4, { scale: 2.5, opacity: 0 }, { easing: 'quadOut' })
                                .call(() => {
                                    this.clickFlag = true
                                    if(this.clickTime<3){
                                        this.guideFinger.active = true
                                    }                                    
                                    lightNode.removeFromParent()
                                    lightNode.destroy()
                                })
                                .start()
                        })
                        .start()
                }, 10);
            })
            .start()
    }
    private UpFunc1(sprite: cc.Sprite, cb: Function) {
        if (sprite.fillRange < 1) {
            sprite.fillRange += 0.05
        } else {
            this.unschedule(this.UpFunc)
            cb()
        }
    }
    private UpFunc(sprite: cc.Sprite, cb: Function) {
        if (sprite.fillRange < 1) {
            sprite.fillRange += 0.075;
        } else {
            // 使用保存的函数引用来取消调度
            if (sprite['scheduledFunction']) {
                this.unschedule(sprite['scheduledFunction']);
                delete sprite['scheduledCloseFunction']; // 清理引用
            }
            cb();
        }
    }
    private resize() {
        const canvasValue: any = cc.Canvas.instance;
        let frameSize = cc.view.getFrameSize();
        let isVerTical = cc.winSize.height > cc.winSize.width
        this.bg.spriteFrame = isVerTical ? this.bgArr[0] : this.bgArr[1]
        this.topNode.scale = isVerTical ? 1 : 1.5
        this.bottomNode.scale = isVerTical ? 1 : 1.5
        this.horPayNode.active = !isVerTical
        this.verPayNode.active = isVerTical
        if (isVerTical) {//竖屏
            if (cc.winSize.width / cc.winSize.height > 0.7) {
                cc.Canvas.instance.fitHeight = true;
                cc.Canvas.instance.fitWidth = false;
            } else {
                cc.Canvas.instance.fitHeight = false;
                cc.Canvas.instance.fitWidth = true;
            }
        } else {
            cc.Canvas.instance.fitHeight = true;
            cc.Canvas.instance.fitWidth = false;
        }
        cc.director.getScene().getComponentsInChildren(cc.Widget).forEach(function (t) {
            t.updateAlignment()
        });
        this.topNode.getComponent(cc.Widget).top = isVerTical ? 248.6 : 30
        this.topNode.getComponent(cc.Widget).left = isVerTical ? 0 : cc.winSize.width / 20
        this.bottomNode.getComponent(cc.Widget).right = isVerTical ? 0 : cc.winSize.width / 8
        this.resultNode.scale = isVerTical ? 1 : 1.5
        this.tipLabel.node.active = isVerTical
        this.tipLabel1.node.active = !isVerTical
    }
    private cashoutFunc() {
        console.log('跳转');
        this.canPlayMusic && cc.audioEngine.play(RESSpriteFrame.instance.clickAudioClip, false, 1)
        PlayerAdSdk.gameEnd()
        PlayerAdSdk.jumpStore()
    }
    protected onDisable(): void {
        this.cashOutBtn.off(cc.Node.EventType.TOUCH_START, this.cashoutFunc, this)
    }
}   
